<?php

namespace App\Http\Livewire;

use App\Models\Team;
use App\Traits\ModalTrait;
use Livewire\Component;

class TeamLinkAddForm extends Component
{

    use ModalTrait;

    public $name;
    public $url;
    public $team;

    protected $rules = [
        'name' => 'bail|required|max:150',
        'url' => 'bail|required'
    ];

    public function mount(Team $team)
    {
        $this->team = $team;
    }

    public function addLink()
    {
        $this->validate();

        $this->team->links()->create([
            'name' => $this->name,
            'url' => $this->url,
        ]);

        $this->hide();

        $this->emitUp('loadModelRelation', 'links');
    }

    public function render()
    {
        return view('livewire.team.team-link-add-form');
    }
}
